Crate histogram [−] [src]
A native rust implementation of a histogram and percentiles which can offer
specified precision across the full range of stored values. This library is
inspired by the HdrHistogram
project.
Goals
- maintain precision across full value range
- provide percentile metrics for stored data
- pre-allocated datastructure
Future work
- unknown
Usage
Create a new histogram, call increment for every value, retrieve percentile stats.
Note that the incremented and decremented values have the precision which is given upon creation of the histogram (by default 3 decimals). This means that increment of x and decrement of y might lead net effect of zero, if x and y are of similar size.
Example
Create a histogram, increment values, show percentiles
use histogram::Histogram; // create a histogram with default config let mut histogram = Histogram::new(); let mut value = 0; for i in 1..100 { histogram.increment(i); } // print percentiles from the histogram println!("Percentiles: p50: {} ns p90: {} ns p99: {} ns p999: {}", histogram.percentile(50.0).unwrap(), histogram.percentile(90.0).unwrap(), histogram.percentile(99.0).unwrap(), histogram.percentile(99.9).unwrap(), ); // print additional statistics println!("Latency (ns): Min: {} Avg: {} Max: {} StdDev: {}", histogram.minimum().unwrap(), histogram.mean().unwrap(), histogram.maximum().unwrap(), histogram.stddev().unwrap(), );
Structs
Bucket |
value-quantized section of |
Config |
A configuration struct for building custom |
Histogram |
the main datastructure |
Iter |
Iterator over a Histogram's buckets. |